﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using SalePartial.Utility;
using System.Data;
using SalePartial.Model;
using SalePartial.IDAL;

namespace SalePartial.SQLServerDAL
{

    //<DataObjectt(True)> _
    public class XPDeliveryAddres : IXPDeliveryAddres 
    {
        // Methods
        //<DataObjecttMethod(DataObjectMethodType.Delete)> _
        public int Delete(Guid AddressID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("AddressID", AddressID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressDelete]", parameters, RowsAffected);
        }

        //<DataObjecttMethod(DataObjectMethodType.Delete)> _
        public int DeleteByCompanyID(Guid CompanyID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressesDeleteByCompanyID]", parameters, RowsAffected);
        }

        //<DataObjecttMethod(DataObjectMethodType.Delete)> _
        public int DeleteDynamic(string v_whereCondition)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", v_whereCondition) };
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressesDeleteDynamic]", parameters, RowsAffected);
        }

        //<DataObjecttMethod(DataObjectMethodType.Insert)> _
        public int Insert(XPDeliveryAddresInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("AddressID", info.AddressID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("Contact", info.Contact),
			new SqlParameter("Street", info.Street),
			new SqlParameter("City", info.City),
			new SqlParameter("Province", info.Province),
			new SqlParameter("Country", info.Country),
			new SqlParameter("Postcode", info.Postcode),
			new SqlParameter("Phone", info.Phone),
			new SqlParameter("CellPhone", info.CellPhone),
			new SqlParameter("IsDefault", info.IsDefault),
			new SqlParameter("CreateDate", info.CreateDate)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressInsert]", parameters, RowsAffected);
        }

        //<DataObjecttMethod(DataObjectMethodType.Select)> _
        public DataSet SelectAll()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressesSelectAll]", parameters, "XPDeliveryAddres_All");
        }

        //<DataObjecttMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressesSelectByCompanyID]", parameters, "XPDeliveryAddres_ByCompanyID");
        }

        //<DataObjecttMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("WhereCondition", v_whereCondition),
			new SqlParameter("OrderByExpression", v_orderByExpression)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressesSelectDynamic]", parameters, "XPDeliveryAddres_Dynamic");
        }

        //<DataObjecttMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectPaged()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressesSelectPaged]", parameters, "XPDeliveryAddres_Paged");
        }

        //<DataObjecttMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReader(Guid AddressID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("AddressID", AddressID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressSelect]", parameters);
        }

        //<DataObjecttMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressesSelectByCompanyID]", parameters);
        }

        //<DataObjecttMethod(DataObjectMethodType.Select)> _
        public DataSet SelectSingle(Guid AddressID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("AddressID", AddressID) };
            DataSet ds = dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressSelect]", parameters, "XPDeliveryAddres_Single");
            DataTable dt = ds.Tables["XPDeliveryAddres_Single"];
            return ds;
        }

        //<DataObjecttMethod(DataObjectMethodType.Update)> _
        public int Update(XPDeliveryAddresInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("AddressID", info.AddressID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("Contact", info.Contact),
			new SqlParameter("Street", info.Street),
			new SqlParameter("City", info.City),
			new SqlParameter("Province", info.Province),
			new SqlParameter("Country", info.Country),
			new SqlParameter("Postcode", info.Postcode),
			new SqlParameter("Phone", info.Phone),
			new SqlParameter("CellPhone", info.CellPhone),
			new SqlParameter("IsDefault", info.IsDefault),
			new SqlParameter("CreateDate", info.CreateDate)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPDeliveryAddressUpdate]", parameters, RowsAffected);
        }

    }



}
